package com.dragon.repository.domain.dto;

import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.Product;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProductDTO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "商品编号")
    private Integer id;

    @ApiModelProperty(value = "商品名称")
    private String name;

    @ApiModelProperty(value = "SPU规格列表")
    private String spuSpecification;

    @ApiModelProperty(value = "类别编号")
    private Integer categoryId;

    @ApiModelProperty(value = "品牌编号")
    private Integer brandId;

    @ApiModelProperty(value = "基本计量单位")
    private Integer productUnitId;

    @ApiModelProperty(value = "状态1上架2下架")
    private Integer status;

    @ApiModelProperty(value = "备注")
    private String info;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "公司id")
    private Integer companyId;

    @ApiModelProperty(value = "价格")
    private Double price;

    @ApiModelProperty(value = "产品单位名称")
    private String productUnitName;

    @ApiModelProperty(value = "类别名称")
    private String categoryName;

    public ProductDTO() {}

    public ProductDTO(Product entity) {
        BeanUtils.copyProperties(entity,this);
    }

    public static ProductDTO convert(Product entity) {
        return new ProductDTO(entity);
    }

    public static List<ProductDTO> convertList(List<Product> list) {
        List<ProductDTO> resultList = new ArrayList<>();
        for (Product entity : list) {
            resultList.add(new ProductDTO(entity));
        }
        return resultList;
    }}
